/* add user code begin Header */
/**
  **************************************************************************
  * @file     at32f415_wk_config.h
  * @brief    header file of work bench config
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */
/* add user code end Header */

/* define to prevent recursive inclusion -----------------------------------*/
#ifndef __AT32F415_WK_CONFIG_H
#define __AT32F415_WK_CONFIG_H

#ifdef __cplusplus
extern "C" {
#endif

/* includes -----------------------------------------------------------------------*/
#include "at32f415.h"

/* private includes -------------------------------------------------------------*/
/* add user code begin private includes */
#include "wk_system.h"
#include "stdio.h"
#include "i2c_application.h"

#include "flexible_button.h"

#include "FreeRTOS.h"
#include "task.h"
#include "app_task.h"

#include "sht30.h"
//#include "sht40.h"

#include "ssd1306.h"
#include "ssd1306_fonts.h"

#include "kalmanfilter.h"
#include "pid.h"


/* User defines -------------------------------------------------------------*/
#define USE_RTOS                                1           //0 不使用RTOS    1 使用RTOS


#define USART_TX_BUFF_SIZE                      128
#define USART_RX_BUFF_SIZE                      128

#define TONE_ON()                               tmr_counter_enable(TMR11, TRUE)
#define TONE_OFF()                              tmr_counter_enable(TMR11, FALSE)

#define LED_ON()                                gpio_bits_set(LED_GPIO_PORT, LED_PIN)
#define LED_OFF()                               gpio_bits_reset(LED_GPIO_PORT, LED_PIN)

#define ADR_SET_HIGH()                          gpio_bits_set(ADSET_GPIO_PORT, ADSET_PIN)
#define ADR_SET_LOW()                           gpio_bits_reset(ADSET_GPIO_PORT, ADSET_PIN)

/* user can only modify the dma define value */
#define DMA1_CHANNEL1_BUFFER_SIZE               USART_TX_BUFF_SIZE
#define DMA1_CHANNEL1_MEMORY_BASE_ADDR          (uint32_t)usart_tx_buff
//#define DMA1_CHANNEL1_PERIPHERAL_BASE_ADDR  0

#define DMA1_CHANNEL2_BUFFER_SIZE               USART_RX_BUFF_SIZE
#define DMA1_CHANNEL2_MEMORY_BASE_ADDR          (uint32_t)usart_rx_buff
//#define DMA1_CHANNEL2_PERIPHERAL_BASE_ADDR   0

#define LED_PIN             GPIO_PINS_2
#define LED_GPIO_PORT       GPIOA
#define ADSET_PIN           GPIO_PINS_2
#define ADSET_GPIO_PORT     GPIOB
#define ADC_PIN             GPIO_PINS_3
#define ADC_GPIO_PORT       GPIOA
#define PWM_PIN             GPIO_PINS_6
#define PWM_GPIO_PORT       GPIOA
#define K2_PIN              GPIO_PINS_3
#define K2_GPIO_PORT        GPIOB
#define BUTTON_PIN          GPIO_PINS_4
#define BUTTON_GPIO_PORT    GPIOB
#define K1_PIN              GPIO_PINS_5
#define K1_GPIO_PORT        GPIOB
#define TONE_PIN            GPIO_PINS_9
#define TONE_GPIO_PORT      GPIOB


//按键数量定义
enum {
	button = 0,
	k1,
	k2,
	FLEX_BUTTON_MAX
};


/* exported value ------------------------------------------------------- */
extern uint8_t usart_tx_buff[];
extern uint8_t usart_rx_buff[];

//按键变量
extern __IO uint8_t		    BUTTON_SINGLE_Click_Flag;
extern __IO uint8_t		    BUTTON_DOUBLE_Click_Flag;
extern __IO uint8_t	    	BUTTON_SHORT_PRESS_Flag;
extern __IO uint8_t	    	BUTTON_LONG_PRESS_Flag;

extern __IO uint8_t	    	K1_SINGLE_Click_Flag;
extern __IO uint8_t	    	K1_DOUBLE_Click_Flag;
extern __IO uint8_t	    	K1_SHORT_PRESS_Flag;
extern __IO uint8_t	    	K1_LONG_PRESS_Flag;

extern __IO uint8_t		    K2_SINGLE_Click_Flag;
extern __IO uint8_t		    K2_DOUBLE_Click_Flag;
extern __IO uint8_t		    K2_SHORT_PRESS_Flag;
extern __IO uint8_t	    	K2_LONG_PRESS_Flag;


/* exported functions ------------------------------------------------------- */
void wk_system_clock_config(void);
void wk_periph_clock_config(void);
void wk_debug_config(void);
void wk_nvic_config(void);
void wk_gpio_config(void);
void wk_adc1_init(void);
void wk_i2c1_init(void);
void wk_i2c2_init(void);
void wk_usart1_init(void);
void wk_tmr9_init(void);
void wk_tmr10_init(void);
void wk_tmr11_init(void);
void wk_wdt_init(void);
void wk_dma1_channel1_init(void);
void wk_dma1_channel2_init(void);
void wk_dma_channel_config(dma_channel_type* dmax_channely, uint32_t peripheral_base_addr, uint32_t memory_base_addr, uint16_t buffer_size);

/* user code exported functions */
void user_button_init(void);
void enter_standby_mode(void);

#ifdef __cplusplus
}
#endif

#endif
